var map = new BMap.Map("map_main");
// 创建地图实例  
map.centerAndZoom(new BMap.Point(118.82496707, 36.68278473), 8);
map.enableScrollWheelZoom(true);
// 初始化地图，设置中心点坐标和地图级别

var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); 
map.addControl(top_right_navigation);  
// 添加缩放工具

// 百度地图API功能

$.getJSON("map_data.json", function(json){
	for(var i=0; i<json.length; i++){
		var sContent = 
		"<h4 style='margin:0 0 5px 0; padding:0.2em 0'>" + json[i].store_name + "</h4>" +
		"<img style='float:right; margin:4px' id='imgDemo' src='" + json[i].img_url + "' width='139' height='104' title='店铺名称'/>" +
		"<p style='width:300px;'>地址：" + json[i].add + "</p>" +
		"<p>电话：" + json[i].tel + "</p>" +
		"<p>人气：" + json[i].hot + "</p>" +
		"<p>人均消费：" + json[i].consume + "</p>";
		createMark(json[i].point_lng,json[i].point_lat,sContent);
	}
});
var createMark = function (lng, lat, info_html){
	var point = new BMap.Point(lng, lat);
	var infoWindow = new BMap.InfoWindow(info_html);  // 创建信息窗口对象
	var marker = new BMap.Marker(point);
	map.addOverlay(marker);
	marker.addEventListener("click", function(){
	   this.openInfoWindow(new BMap.InfoWindow(info_html));
	   //图片加载完毕重绘infowindow
	   document.getElementById('imgDemo').onload = function (){
		   new BMap.InfoWindow(info_html).redraw();   //防止在网速较慢，图片未加载时，生成的信息框高度比图片的总高度小，导致图片部分被隐藏
	   }
	});
}